package com.pig4cloud.pigx.ruralLibrary;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pig4cloud.pigx.ruralLibrary.api.entity.BookUserEntity;
import com.pig4cloud.pigx.ruralLibrary.api.entity.NewUsers;
import com.pig4cloud.pigx.ruralLibrary.mapper.BookUserMapper;
import com.pig4cloud.pigx.ruralLibrary.service.BookUserService;
import com.pig4cloud.pigx.ruralLibrary.service.RecommendManageService;
import com.pig4cloud.pigx.ruralLibrary.service.impl.RecommendManageServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@SpringBootTest
public class text {

	@Autowired(required = false)
	private BookUserMapper mapper;

	@Autowired(required = false)
	private BookUserService service;

	@Autowired(required = false)
	private  RecommendManageService recommendManageService;

	public static void main(String[] args) {
		String path = "/digitallibrary/file/lengleng/da4a9fc5e0e24b90871fdc67395e65d5.jpg";
		String[] parts = path.split("/");
		String bucketName = parts[parts.length - 2];
		String fileName = parts[parts.length - 1];

		System.out.println("Bucket Name: " + bucketName);
		System.out.println("File Name: " + fileName);

	}

	@Test
	public void test() {
		//获取近七天日期
		List<String> dateList = new ArrayList<>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		for (int i = 0; i < 8; i++) {
			Date date = DateUtils.addDays(new Date(), -i);
			String formatDate = sdf.format(date);
			dateList.add(formatDate);
		}
		List<NewUsers> newUsersList = mapper.getNewUsers(dateList, 2,"");
		//创建一个arraylist对象
		List<NewUsers> list = new ArrayList<>();
		//外层七天循环  循环七次
		for (int i = 0; i < dateList.size(); i++) {
			//创建封装类对象  循环七次 创建七个
			NewUsers newUsers = new NewUsers();
			//将近七天日期添加进封装类中
			newUsers.setCreateTime(dateList.get(i));
			boolean bool = false;
			//创建内循环 根据查询出已有的数量 循环次数
			for (int m = 0; m < newUsersList.size(); m++) {
				if (dateList.get(i).equals(newUsersList.get(m).getCreateTime())) {
					newUsers.setNewUsers(newUsersList.get(m).getNewUsers());
					bool = true;
					break;
				}
			}
			if (!bool) {
				newUsers.setNewUsers("0");
			}
			list.add(newUsers);
		}
		System.out.println(list);
	}

	@Test
	public void test2() {
		BookUserEntity bookUser = new BookUserEntity();
		bookUser.setUserName("15136247187");
		bookUser.setUserCode("123456");
		bookUser.setCol2("y/cCrULtYm/V/+ZG1iiQrw==");
//		service.saveUser(bookUser);
	}

	@Test
	public void test3() {
		List<BookUserEntity> list = new ArrayList<>();
		BookUserEntity bookUser = new BookUserEntity();
		BookUserEntity bookUser1 = new BookUserEntity();
		BookUserEntity bookUser2 = new BookUserEntity();
		bookUser.setUserName("15136247175");
		bookUser1.setUserName("15136247173");
		bookUser2.setUserName("15136247176");
		list.add(bookUser);
		list.add(bookUser1);
		list.add(bookUser2);

		QueryWrapper<BookUserEntity> sysUserQueryWrapper = new QueryWrapper<>();
		sysUserQueryWrapper.in("user_name", list.stream().map(BookUserEntity::getUserName).collect(Collectors.toList()));
		List<BookUserEntity> list1 = service.list(sysUserQueryWrapper);
		System.out.println(list1);
	}
}





